package com.example.springbootemployees.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//这里我们扩展使用了SpringMVC 配置的目的即使我们在地址栏输入/ 或/index.html后会跳转都首页，这样我们就不必在controller层编写调换首页的控制，这是我们下面重写方法的作用，当然也很其他的方法可以重写，，也就有许多其他的作用等地我们发掘。
@Configuration

public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHanderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/index.html","/user/login","/","/asserts/css/**","/asserts/img/**","/asserts/js/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }
}
